using System;
using Microsoft.SPOT;
using System.Collections;

namespace N2Plus_GPS
{
    /// <summary>
    /// Container class for a map sector
    /// </summary>
    public class Sector
    {
        #region Private Variables
        #endregion

        #region Constructor
        #endregion

        #region Properties
        /// <summary>
        /// Stores all the GPS Points that define this sector
        /// </summary>
        public ArrayList GPSArea
        {
            get;
            set;
        }

        /// <summary>
        /// Specify if this sector defines the start finish sector
        /// </summary>
        public bool StartFinish
        {
            get;
            set;
        }

        /// <summary>
        /// Sector name
        /// </summary>
        public string Name
        {
            get;
            set;
        }

        private TimeSpan _FastestSectorTime = default(TimeSpan);
        /// <summary>
        /// The fastest sector time recorded
        /// </summary>
        public TimeSpan FastestSectorTime
        {
            get { return _FastestSectorTime; }
            set { _FastestSectorTime = value; }
        }

        private TimeSpan _FastestLapSectorTime = default(TimeSpan);
        /// <summary>
        /// The sector time of the fastest lap
        /// </summary>
        public TimeSpan FastestLapSectorTime
        {
            get { return _FastestLapSectorTime; }
            set { _FastestLapSectorTime = value; }
        }
     

        private TimeSpan _SectorTime = default(TimeSpan);
        /// <summary>
        /// The recorded sector time
        /// </summary>
        public TimeSpan SectorTime
        {
            get { return _SectorTime; }
            set 
            { 
                _SectorTime = value;
                if (_FastestSectorTime == default(TimeSpan))
                {
                    //First sector times
                    _FastestSectorTime = _SectorTime;
                    _FastestLapSectorTime = _SectorTime;
                }
                else
                {
                    if (_SectorTime < _FastestSectorTime)
                    {
                        _FastestSectorTime = _SectorTime;
                    }
                }
            }
        }

        /// <summary>
        /// Stores the Sector Index for quick reference to fastest lap sectors
        /// </summary>
        public int SectorIndex
        {
            get;
            set;
        }
        #endregion

        #region Methods
        #endregion

        #region Overrides
        /// <summary>
        /// Overrides for more desired output of string
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return GPSArea != null ? "GPS Area Points :" + GPSArea.Count : "No GPS Area specified";
        }
        #endregion

    }
}
